package com.woniuxy.controller;

import com.woniuxy.entity.Training;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.entity.dto.TrainingDto;
import com.woniuxy.entity.dto.UserTrainingDto;
import com.woniuxy.service.TrainingsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.temporal.TemporalAccessor;

/**
 * @Author：jojo
 * @Date：2022/3/7 14:44
 * @Description :TODO
 */

@RestController
@RequestMapping("/trainings")
public class TrainingsController {
    @Autowired(required = false)
    TrainingsService trainingsService;

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/7:16:02  <br/>
     * Description:查询培训项目
     */
    @ApiOperation(value="查询培训项目")
    @PostMapping("/findTraining/{currentPage}/{pageSize}")
    public ResponseEntity findTraining(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize, @RequestBody Training training){
        return  trainingsService.findTraining(currentPage,pageSize,training);
    }



    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/7:19:05  <br/>
     * Description:删除培训项目
     */
    @ApiOperation(value="删除培训项目")
    @DeleteMapping("/deleteOne/{id}")
    public ResponseEntity deleteOne(@PathVariable int id){
        return trainingsService.deleteOne(id);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/7:19:10  <br/>
     * Description:添加培训项目
     */
    @ApiOperation(value="添加培训项目")
    @RequestMapping("/addOne")
    public ResponseEntity addOne(@RequestBody TrainingDto trainingDto){

        System.out.println(trainingDto.getTraining());
        System.out.println(trainingDto.getCourseidList().toString());
        return trainingsService.addOne(trainingDto);
    }


    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/7:19:25  <br/>
     * Description:修改培训项目
     */
    @ApiOperation(value="修改培训项目")
    @RequestMapping("/updateById/")
    public ResponseEntity updateById(@RequestBody Training training){
        return trainingsService.updateById(training);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/9:19:31  <br/>
     * Description:通过trainingId查询crouseId
     */
    @ApiOperation(value="通过trainingId查询crouseId")
    @PostMapping("/findCrouseBytrainingId")
    public ResponseEntity findCrouseBytrainingId(@RequestBody Training training){
        return  trainingsService.findCrouseBytrainingId(training);
    }

    /*
     * Description :通过用户id查出所有培训和培训下的所有课程及进度
     * ChangeLog : 1. 创建 (2022/3/11 2:20 [10604]);
     ** @param null
     * *  @return null
    */
    @ApiOperation(value = "查询用户参加的所有培训")
    @PostMapping("/findTrainingByUserId")
    public ResponseEntity findTrainingByUserId(@RequestBody User user){
        return trainingsService.findTrainingByUserId(user);
    }
    /*
     *功能描述
     * @Author: jojo
     * @Date: 2022/3/12 11:48
     * @param currentPage
     * @param pageSize
     * @param training
     * @return com.woniuxy.entity.ResponseEntity
     */
    @ApiOperation(value="通过Id查询TrainingId")
    @RequestMapping("/findTrainingById/{currentPage}/{pageSize}/{id}")
    public ResponseEntity findTrainingById(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize, @PathVariable("id") int id){
        return  trainingsService.findTrainingById(currentPage,pageSize,id);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/15:19:24  <br/>
     * Description:根据搜索条件查询培训项目
     */
    @ApiOperation(value="根据搜索条件查询培训项目")
    @PostMapping("/findTrainingBySearch/")
    public ResponseEntity findTrainingBySearch(@RequestBody UserTrainingDto userTrainingDto){
        return trainingsService.findTrainingBySearch(userTrainingDto);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/16:10:12  <br/>
     * Description:根据课程id查询课程所在的培训id
     */
    @ApiOperation(value="根据课程id查询课程所在的培训id")
    @PostMapping("/findTrainingIdByCrouseId/{id}")
    public ResponseEntity findTrainingIdByCrouseId(@PathVariable int id){
        return trainingsService.findTrainingIdByCrouseId(id);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/17:10:20  <br/>
     * Description:根据用户id和培训id插入报名信息(报名)
     */
    @ApiOperation(value="根据用户id和培训id插入报名信息(报名)")
    @PostMapping("/apply/{userid}/{trainingid}")
    public ResponseEntity apply(@PathVariable int userid,@PathVariable int trainingid){
        return trainingsService.apply(userid,trainingid);
    }

    /**
     * Auther: gaoyi  <br/>
     * Date: 2022/3/17:14:42  <br/>
     * Description:根据用户id查询用户未报名的培训
     */
    @ApiOperation(value="根据用户id查询用户未报名的培训")
    @PostMapping("/findNotApplyTrainingByUserId/{currentPage}/{pageSize}/{userid}")
    public ResponseEntity findNotApplyTrainingByUserId(@PathVariable("currentPage") int currentPage, @PathVariable("pageSize") int pageSize,@PathVariable int userid){
        return trainingsService.findNotApplyTrainingByUserId(currentPage,pageSize,userid);
    }
}
